<?php

namespace Backend\Modules\Video\Controllers;

use Library\Constant\Constant;
use \Phalcon\Paginator\Adapter\Model as Paginator;
use Phalcon\Mvc\Model\Resultset;
use Library\Pagination\Pager as Pager;
use Backend\Modules\Video\Models\Video;
use Backend\Modules\Video\Models\VideoPosterLink;

class VideoPosterController extends \BackendController
{
    public function indexAction()
    {
        $this->assets
            ->addJs('vendor/backend/js/video/video_ajax.js');

        $currentPage = abs($this->request->getQuery('page', 'int', 1));
        $videoPosterLink = VideoPosterLink::find(array(
            "object_type = 'video'"
        ));

        $data = array();
        $tab = $this->request->get('tab') ? $this->request->get('tab') : 'video';

        if ($currentPage == 0) {
            $currentPage = 1;
        }
        $pager = new Pager(
            new Paginator(array(
                'data'  => $videoPosterLink,
                'limit' => Constant::ITEM_PER_PAGE_20 ,
                'page'  => $currentPage,
            )),
            array(
                'layoutClass' => 'Library\Pagination\Pager\Layout\Bootstrap',
                'rangeLength' => 5,
                'urlMask'     => '?page={%page_number}',
            )
        );

        $dataVideoPosterLink = VideoPosterLink::find(array(
            "object_type = 'video_group'"
        ));
        $videoGroupPosterLinks = new Pager(
            new Paginator(array(
                'data'  => $dataVideoPosterLink,
                'limit' => Constant::ITEM_PER_PAGE_20 ,
                'page'  => $currentPage,
            )),
            array(
                'layoutClass' => 'Library\Pagination\Pager\Layout\Bootstrap',
                'rangeLength' => 5,
                'urlMask'     => '?page={%page_number}',
            )
        );

        $this->view->tab = $tab;
        $this->view->videoPosters = $pager;
        $this->view->videoGroupPosterLinks = $videoGroupPosterLinks;
    }
}